package com.yihen.controller;

import com.yihen.dto.Result;
import com.yihen.pojo.Goods;
import com.yihen.service.GoodsService;
import com.yihen.util.UserHolder;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/goods")
@Slf4j
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    // 商品发布
    @PostMapping("/publish")
    public Result publishGoods(@RequestBody Goods goods) {
        return goodsService.publishGoods(goods);
    }

    // 获取个人发布商品
    @GetMapping("/publishedgoods")
    public Result getPublishedGoods() {
        return goodsService.selectAllGoodsByUserId();
    }

    // 根据商品id下架商品
    @DeleteMapping("/remove/{id}")
    public Result deleteByGoodsId(@PathVariable Long id) {
        return goodsService.deleteGoodsById(id);
    }

    // 查询个人发布商品(条件)
    @GetMapping("select/{mode}/{selectMode}/{condition}")
    public Result getMyGoodsByCondition(@PathVariable int mode,@PathVariable int selectMode, @PathVariable String condition) {
        return goodsService.selectMyGoodsByNameOrGoodsId(mode, selectMode,condition);
    }

    // 获取所有商品
    @GetMapping("/allgoods/{mode}")
    public Result getAllGoods(@PathVariable int mode) {
        return goodsService.selectAllGoods(mode);
    }

    // 获取个人待审核商品
    @GetMapping("/checkinggoods/me")
    public Result getMyCheckingGoods() {

        return goodsService.selectCheckingGoodsByUserId();
    }

    // 获取所有待审核商品
    @GetMapping("/checkinggoods/all")
    public Result getCheckingGoods() {

        return goodsService.selectCheckingGoods();
    }

    // 通过审核商品
    @GetMapping("/accept/{goodsId}")
    public Result accept(@PathVariable Long goodsId) {

        return goodsService.acceptGoods(goodsId);
    }


    // 通过商品id查询待审核商品
    @GetMapping("/selectchecking/{mode}/{goodsId}")
    public Result accept(@PathVariable int mode,@PathVariable String goodsId) {
        return goodsService.selectCheckingGoodsByGoodsId(mode, goodsId);
    }

    // 查看商品详情
    @GetMapping("/detail/{goodsId}")
    public Result selectGoodsById(@PathVariable Long goodsId) {
        return goodsService.selectGoodsByGoodsId(goodsId);
    }

}
